package com.driver.manage.controller;



import org.flowable.engine.ProcessEngine;
import org.flowable.engine.ProcessEngineConfiguration;
import org.flowable.engine.impl.cfg.StandaloneProcessEngineConfiguration;

/**
 * @author 86131
 * @title HolidayRequest
 * @date 2023/6/29 14:41
 * @description TODO
 */
public class HolidayRequest {
//    ProcessEngineConfiguration configuration=null;

    public static ProcessEngine holiday() {
        ProcessEngineConfiguration cfg = new StandaloneProcessEngineConfiguration()
                .setJdbcUrl("jdbc:mysql://localhost:3306/ry-cloud?serverTimezone=UTC&nullCatalogMeansCurrent=true")
                .setJdbcUsername("root")
                .setJdbcPassword("root")
                .setJdbcDriver("com.mysql.cj.jdbc.Driver")
                .setDatabaseSchemaUpdate(ProcessEngineConfiguration.DB_SCHEMA_UPDATE_TRUE);
        ProcessEngine processEngine = cfg.buildProcessEngine();
        return processEngine;
    }


//@Test
//    public void testDeploy(){
//    this.before();
//    configuration.setDatabaseSchemaUpdate(ProcessEngineConfiguration.DB_SCHEMA_UPDATE_TRUE);
//        //获取 ProcessEngine 对象
//        ProcessEngine processEngine = configuration.buildProcessEngine();
//        //2。获取 RepositoryService
//        RepositoryService repositoryService = processEngine.getRepositoryService();
//        //3。完成流程的部署操作
//        Deployment deploy = repositoryService.createDeployment()
//                //关联要部署的流程文件
//                .addClasspathResource("processes\\ask_for_approve.bpmn20.xml")
//                .name("司机入驻流程")
//                .deploy();//部署流程
//        System.out.println("deploy.getId() = " + deploy.getId());
//        System.out.println("deploy.getName() = " + deploy.getName());
//
//
//    }
//    /**
//    *查询流程定义信息
//    */
//    @Test
//    public void testDeployQuery(){
//    this.before();
//        ProcessEngine processEngine = configuration.buildProcessEngine();
//        RepositoryService repositoryService = processEngine.getRepositoryService();
//        ProcessDefinition processDefinition = repositoryService.createProcessDefinitionQuery()
//                .deploymentId("1")
//                .singleResult();
//        System.out.println("processDefinition.getId() = " + processDefinition.getId());
//        System.out.println("processDefinition.getName() = " + processDefinition.getName());
//        System.out.println("processDefinition.getDescription() = " + processDefinition.getDescription());
//        System.out.println("processDefinition.getDeploymentId() = " + processDefinition.getDeploymentId());
//    }
//
//    /**
//     * 删除流程实例
//     */
//    @Test
//    public void testDeleteDeploy(){
//        this.before();
//        ProcessEngine processEngine = configuration.buildProcessEngine();
//        RepositoryService repositoryService = processEngine.getRepositoryService();
//        //删除部署的流程   第一个是id  如果已经启动了就不允许删除了
//        //repositoryService.deleteDeployment("1");
//        //第二个参数是级联删除 如果流程启动了也可以删除  相关的任务也一并会删除掉
//        repositoryService.deleteDeployment("1",true);
//    }
//
//    /**
//     * 启动流程实例
//     */
//    @Test
//    public void  testRunprocess(){
//        this.before();
//        ProcessEngine processEngine = configuration.buildProcessEngine();
//        //通过 RuntimeService 来启动流程实例
//        RuntimeService runtimeService = processEngine.getRuntimeService();
//        //构建流程变量   后期通过表单提交
//        Map<String,Object> variables=new HashMap<>();
//        variables.put("name", "张三");
//        //启动流程实例
//        runtimeService.startProcessInstanceByKey("ask_for_approve",variables);
//
//    }

}
